import Vue from 'vue'
import Router from 'vue-router'

const lazyLoading = (name, index = false) => (resolve) => require([`@/views/${name}${index ? '/index' : ''}.vue`], resolve)

Vue.use(Router)

export default new Router({
  mode: 'history',
  scrollBehavior: (to, from, savedPosition) => {
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  },
  routes: [
    {
      path: '/',
      name: 'Home',
      component: lazyLoading('Home', true)
    },
    {
      path: '/other',
      name: 'Other',
      component: lazyLoading('Home/other')
    },
    {
      path: '/screen',
      name: 'Screen',
      component: lazyLoading('Home/screen')
    },
    {
      path: '/push',
      name: 'Push',
      component: lazyLoading('Home/push')
    },
    {
      path: '/protocol',
      name: 'Protocol',
      component: lazyLoading('Home/protocol')
    },
    {
      path: '/share',
      name: 'Share',
      component: lazyLoading('Home/share')
    },
    {
      path: '/webPush',
      name: 'WebPush',
      component: lazyLoading('Home/webPush')
    },
    {
      path: '/iframe/:url',
      name: 'IFrame',
      component: lazyLoading('Home/iframe')
    },
    {
      path: '/detail/:id',
      name: 'Detail',
      component: lazyLoading('Home/detail')
    },
    {
      path: '/category/:id',
      name: 'Category',
      component: lazyLoading('Home/category')
    },
    {
      path: '/list',
      name: 'List',
      component: lazyLoading('Home/list')
    },
    { path: '*', redirect: '/' }
  ]
})
